package model;

import context.*;

import java.awt.Graphics2D;
import java.awt.geom.Point2D;

public class Linjal implements Context.Constants
{ //private static final boolean DEBUG=true; // Overriding Context.Constants.DEBUG

  private float x0;
  private float y0;
  private float length;
  
  public Linjal(float x0,float y0,float length)
  { this.x0=x0;
    this.y0=y0;
    this.length=length;
  }
  
  public void paintVertikal(Graphics2D g,double[] dist,String[] label)
  { double d10=10;
    double heightL=length;
    double xL=x0;
    double yL=y0;
    Util.drawLine(g,xL,yL-2*d10,xL,yL+heightL+2*d10);
    double prevDist=0;
    for(int i=0;i<dist.length;i++)
    { double dd=dist[i];
      Util.drawLine(g,xL-d10,yL+dd,xL+d10,yL+dd); // Tverrlinje etter 'dist[i]'
      double diff=dd-prevDist;
      if(diff>0.20)
      {  
//        Util.label(g,""+(int)(diff*100+0.5),xL,yL+(prevDist+diff/2));
        try { Util.label(g,label[i],xL,yL+(prevDist+diff/2)); }
        catch(Exception ignore) {}
      }
      prevDist=dd;
    }
  }
  
  public void paintHorisontal(Graphics2D g,double[] dist,String[] label)
  {
    double d10=10;
    double widthL=length;
    double xL=x0;
    double yL=y0;
    Util.drawLine(g,xL-2*d10,yL,xL+widthL+2*d10,yL);
    double prevDist=0;
    for(int i=0;i<dist.length;i++)
    { double dd=dist[i];
      Util.drawLine(g,xL+dd,yL-d10,xL+dd,yL+d10); // Tverrlinje etter 'dist[i]'
      double diff=dd-prevDist;
      if(diff>0.30)
      {  
//        Util.label(g,""+(int)(diff*100+0.5),xL+(prevDist+diff/2),yL);
        try { Util.label(g,label[i],xL+(prevDist+diff/2),yL); }
        catch(Exception ignore) {}
      }
      prevDist=dd;
    }    
  }
}
